﻿<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="java.util.*"%>
<%@page import="com.lmpop.frame.util.Config"%>
<%@ page import="com.lmpop.createIndex.search.*"%>
<%@ page import="com.lmpop.trade.ti_auction_log.*"%>
<%@ page import="com.lmpop.trade.ti_auction.*"%>
<jsp:useBean id="pageUtil" class="com.lmpop.frame.util.PageUtil" scope="page" /><jsp:useBean id="bean" class="com.lmpop.frame.util.RandomID" scope="page"/><%!public String getPartLength(String key, int num) {
		if (key.equals(""))
			return "";
		if (key.length() > num)
			key = key.substring(0, num) + "...";
		return key;
	}

public String getDateStr(String in_date, String type) {
		if (in_date.equals(""))
			return "";
		if (in_date.length() >= 8) {
			String yeard = in_date.substring(0, 4);
			String monthd = in_date.substring(4, 6);
			String dayd = in_date.substring(6, 8);
			String h=in_date.substring(8,10);
			String m=in_date.substring(10,12);
			String s=in_date.substring(12,14);
			if (type.equals("")) {
				in_date = yeard + "-" + monthd + "-" + dayd;
			}else if (type.equals("l")) {
				in_date = yeard + "-" + monthd + "-" + dayd+" "+h+":"+m+":"+s;
			} else {
				in_date = monthd + "-" + dayd;
			}
		}
		return in_date;	
	}
	
		public String getBid_state(String auction_id){
			
			AuctionviewIndexFiles auctionviewIndex = new AuctionviewIndexFiles();
		    String bid_state = "";
			Hashtable map3 = new Hashtable();
			map3.put("auction_id",auction_id);
			try{
			List auctionviewList2 = auctionviewIndex.getAuctionviewList(map3);
					if(auctionviewList2!=null&&auctionviewList2.size()>0){
						for(int i=0;i<auctionviewList2.size();i++){
								Hashtable map = (Hashtable)auctionviewList2.get(i);
										if(map.get("bid_state")!=null){
												bid_state = map.get("bid_state").toString();
										}
										if(bid_state.equals("1")){
												return bid_state;		
										}
					    }
					}
			}catch(Exception e){
				e.printStackTrace();
			}
			return bid_state;		
		}
	
	%>
<%
	String info_id = bean.GenTradeId();
	request.setCharacterEncoding("utf-8");
	String user_id="",user_type="";
	if(session.getAttribute("session_user_id")!=null){
		user_id = session.getAttribute("session_user_id").toString();
	}
	
	if(session.getAttribute("session_user_type")!=null){
		user_type = session.getAttribute("session_user_type").toString();
	}
	int limit = 10;
	
	int start = 0, end = limit;
	int startPage = 1;
	if (request.getParameter("start") != null
			&& !request.getParameter("start").equals("")) {
		start = Integer.parseInt(request.getParameter("start"));
	}
	if (start == 1 || start == 0) {
		start = 0;
		startPage = 1;
	} else {
		startPage = start;
		start = (start - 1) * limit;
	}
	end = start + limit;
	
	CategoryIndexFiles categoryIndex = new CategoryIndexFiles();
	CategoryattrIndexFiles categoryattrIndex = new CategoryattrIndexFiles();
	String categorySelect = categoryIndex.getCategorySelect("","2");
	AttachIndexFiles attachIndex = new AttachIndexFiles();
	GoodsIndexFiles goodsIndex = new GoodsIndexFiles();
	Config configa = new Config();
	configa.init();
	String rootpath = configa.getString("rootpath");
	String goods_article_path = configa.getString("goods_article_path");
	String noimg_path = configa.getString("noimg_path");
	Hashtable paraMap = new Hashtable();
	String auction_id="";
	if(request.getParameter("auction_id") != null && !request.getParameter("auction_id").equals("")){
		auction_id = request.getParameter("auction_id").toString();
		paraMap.put("auction_id",auction_id);		
	}
	AuctionIndexFiles auctionIndex = new AuctionIndexFiles();
	List auctionList = auctionIndex.getAuctionList(paraMap);
	Ti_auction_logInfo auctionview = new  Ti_auction_logInfo();
	Ti_auctionInfo auctionInfo = new Ti_auctionInfo();
	List auctionviewList = auctionview.getListByPage(paraMap,start,limit);
	
	String max_price = auctionview.getMaxBidPrice(paraMap);
	int counter = 0;
	if(auctionviewList!=null&&auctionviewList.size()>0){
		counter = auctionviewList.size();
	}
	
	/*if (end > counter) {
		end = counter;
		start = (((counter - 1) / limit + 1) - 1) * limit;
	}*/
	String url = "shop_auction_veiw.html";
	String pageString = pageUtil.getPageString(url,counter,limit,start,request);
	
	
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>拍卖活动-</title>
<LINK href="/templets/html/css/paimai.css"  rel="stylesheet">
<link href="/templets/html/shop/css/style.css" rel="stylesheet" type="text/css" />
<link  href="/templets/html/shop/css/Home.css" rel="stylesheet"/>
<SCRIPT src="/templets/html/shop/js/taobao.js"></SCRIPT>
<SCRIPT src="/templets/html/shop/js/nav_style_num.js"></SCRIPT>
<script type="text/javascript" src="/js/jquery-1.4.2.min.js"></script>
<LINK href="/templets/html/shop/css/paimai.css"  rel="stylesheet">
<script type="text/javascript" src="/templets/html/shop/js/gotime.js"></script>
<script type='text/javascript' src='/dwr/engine.js'></script>
<script type='text/javascript' src='/dwr/util.js'></script>
<script type='text/javascript' src='/dwr/interface/Ti_subscribeInfo.js'></script>
<script type='text/javascript' src='/templets/html/shop/js/_shop.js'></script>
<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/interface/Ti_voucherInfo.js'></script>
</head>
<body>
<script> 
  document.write("<s" + "cript type='text/javascript' src='/templets/html/shop/top.jsp?" + Math.random() + "'></scr" + "ipt>"); 
  TB.Header.init(); 
</script>
<!--ban-->
<DIV class="block box">
  <DIV >当前位置: <A href="/data/shop.html">首页</A> <CODE>&gt;</CODE> 拍卖活动</DIV>
</DIV>
<DIV class=blank></DIV>
</div>
</div>
</div>
<DIV class=AreaR>
  <DIV class=box>
    <DIV class=box_1>
      <H3><SPAN>拍卖商品</SPAN></H3>
      <%

								
								Hashtable map = new Hashtable();
								String _auction_id="",attr_desc="",publish_date="",auction_name="",auction_desc="", good_id = "",good_name = "",rate_price="",start_date="",end_date="", start_price = "", a_price = "",file_path="";
								String bid_state="",auction_state="",state_val="0",cust_id="";	
									if(auctionList!=null&&auctionList.size()>0){
										
											map = (Hashtable)auctionList.get(0);
											
											if (map.get("auction_id") != null) {
												_auction_id = map.get("auction_id").toString();
											}
											if (map.get("auction_name") != null) {
												auction_name = map.get("auction_name").toString();
											}
											if (map.get("attr_desc") != null) {
												attr_desc = map.get("attr_desc").toString();
											}
											if (map.get("auction_desc") != null) {
												auction_desc = map.get("auction_desc").toString();
											}
											if (map.get("good_id") != null) {
												good_id = map.get("good_id").toString();
											}
											if (map.get("goods_name") != null) {
												good_name = map.get("goods_name").toString();
												
											}
											if (map.get("publish_date") != null) {
												publish_date = map.get("publish_date").toString();
												publish_date=getDateStr(publish_date,"");
											}
											if (map.get("start_date") != null) {
												start_date = map.get("start_date").toString();
												start_date=getDateStr(start_date,"l");
											}
											if (map.get("end_date") != null) {
												end_date = map.get("end_date").toString();
												end_date=getDateStr(end_date,"l");
											}
											if (map.get("start_price") != null) {
												start_price = map.get("start_price").toString();
											}
											if (map.get("rate_price") != null) {
												rate_price = map.get("rate_price").toString();
											}
											if (map.get("a_price") != null) {
												a_price = map.get("a_price").toString();
											}
											if (map.get("file_path") != null) {
												file_path = map.get("file_path").toString();
											}
											if(max_price.equals("")){
													max_price = start_price;
											}
										long start_date_int = 0,end_date_int=0,now_date_int=0;

										java.text.DateFormat df2 = new java.text.SimpleDateFormat("yyyy-MM-dd");
										
										start_date_int = df2.parse(start_date).getTime();
										end_date_int = df2.parse(end_date).getTime();
										now_date_int = new java.util.Date().getTime();	
										bid_state =  getBid_state(_auction_id);
										int s_year=0,s_month=0,s_date=0;
										Calendar cal = Calendar.getInstance();
											cal.setTime(df2.parse(end_date));
											s_year = cal.get(Calendar.YEAR);
											s_month = cal.get(Calendar.MONTH);
											s_date = cal.get(Calendar.DAY_OF_MONTH);
										
										if(now_date_int >= start_date_int && now_date_int <= end_date_int){
												auction_state="<font color='red'>该拍卖活动正在进行中</font>";
												state_val = "0";
											}
											if(now_date_int < start_date_int){
												auction_state="该拍卖活动还没开始";
												state_val = "1";
											}
											if(now_date_int > end_date_int){
												auction_state="该拍卖活动已经结束";
												state_val = "1";
											}
											
											if(bid_state.equals("1")){
												auction_state="因有人中标而结束";
												state_val = "1";
											}	
											List custlist =auctionInfo.getCustIdByPk(_auction_id);
											if(custlist!=null&&custlist.size()>0){
												Hashtable custMap = (Hashtable)custlist.get(0);
												if(custMap.get("cust_id")!=null){
													cust_id = custMap.get("cust_id").toString();
												}
											}
							%>
      <FORM name="theForm" action="/doTradeReg.do" method="post">
        <DIV class=boxCenterList>
		 <div style="MARGIN-RIGHT: 12px; TEXT-ALIGN: center; width:250px; float:left; margin-top:20px; display:inline "> <IMG style="VERTICAL-ALIGN: middle;border:1px solid #dedede; padding:2px" alt="<%=good_name%>" src="<%=file_path%>" width="250" height="270" border=0> </div>
        <UL class="group">
       
         <LI > 商品名称：<strong style=" font-size:16px"><a href="/data/goods/<%=publish_date%>/<%=good_id %>.html"><%=good_name%></a></strong></LI>
          <LI >当前价格：<strong><font><%=max_price%></font></strong>元</LI>
          <LI >起止时间：<strong><%=start_date%> -- <%=end_date%></strong></LI>
          <LI >起拍价：<strong><font><%=start_price%></font></strong>元</LI>
          <LI >加价幅度：<strong><%=rate_price%></strong>元</LI>
          <LI >一口价：<strong><font><%=a_price%></font></strong>元</LI>
        <LI > <%=auction_state%>
          <%if(state_val.equals("0")){%>
          ，距离结束时间还有： <span id="TimeCounter_0" style="margin:5px;padding:2px;width:140px; font-size:12px; font-weight:bold; color:#b30000;"></span>
          <SCRIPT> 
										target[target.length]=new Date(<%=s_year%>,<%=s_month%>,<%=s_date%>,00,00,00).getTime(); 
										time_id[time_id.length]="TimeCounter_0"; 
										</SCRIPT>
          <%}%>
          <BR/>
          <%if(state_val.equals("0")){%></LI>
        <LI style="WIDTH: 520px; LINE-HEIGHT: 23px">  我要出价：
          <INPUT class="paimai_area" id="bid_price" size="8" name="bid_price" maxlength="8" />元
          <INPUT type=hidden value="<%=_auction_id%>" name="auction_id"  />
          <INPUT type=hidden value="<%=info_id%>" name="info_id"  />
          <INPUT type=hidden value="0" name="bid_state" id="bid_state"/>
          <INPUT type=hidden value="<%=user_id%>" name="user_id" />
          <INPUT type=hidden  name="bpm_id" value="1234" />
          <INPUT type=hidden  name="jumpurl" value="/shop_auction_view.html?auction_id=<%=_auction_id%>"/>
          <INPUT type="submit" value=出价  class="paimai_btn"  name=bid onclick="return subForm();"  />
          <BR/>
          <%}%>
      </FORM>
      </LI>
      </UL>
	 <!-- <div class="shoucang">
	  <p>喜欢此藏品？还不赶快行动...</p>
	  <p><a href="#"><img src="/templets/html/shop/images/dp_goshopping.gif" border="0" /></a></p>
	  </div> -->
	  
	  
    </DIV>
    <input type="hidden" name="max_price" id="max_price" value="<%=max_price%>" />
    <input type="hidden" name="a_price" id="a_price" value="<%=a_price%>" />
    <input type="hidden" name="rate_price" id="rate_price" value="<%=rate_price%>" />
    <%
								
									}
							%>
  </DIV>


</div>
  <div class="box">
  <DIV class=box_1>
    <H3><SPAN>活动介绍</SPAN></H3>
    <DIV class=boxCenterList><%=auction_desc%></DIV>
  </DIV>
  </div>
<DIV class=box>
  <DIV class=box_1>
    <H3><SPAN>出价记录</SPAN></H3>
    <DIV class=boxCenterList>
      <TABLE cellSpacing=1 cellPadding=5 width="960" bgColor=#dddddd border=0 class="List_table">
        <TBODY>
          <TR class="td_tr">
            <Td align=middle >买家</Td>
            <Td align=middle >出价</Td>
            <Td align=middle >时间</Td>
            <Td align=middle>状态</Td>
          </TR>
          <%
						
						//String goods_attr = categoryattrIndex.getCatAttrFromStr(attr_desc);
						Hashtable map2 = null;
						String stateid="";
						if(auctionviewList!=null&&auctionviewList.size()>0){
								for(int j=0;j<auctionviewList.size();j++){
										map2 = (Hashtable)auctionviewList.get(j);
										String user_name="",bid_price="",bid_time="",_bid_state="",state="",_user_id="";
											if (map2.get("user_name") != null) {
												user_name = map2.get("user_name").toString();
											}											
											if (map2.get("user_id") != null) {
												_user_id = map2.get("user_id").toString();
											}
											if (map2.get("bid_price") != null) {
												bid_price = map2.get("bid_price").toString();
											}
											if (map2.get("bid_time") != null) {
												bid_time = map2.get("bid_time").toString();
												bid_time = bid_time.substring(0,11);;
											}
											if (map2.get("bid_state") != null) {
												_bid_state = map2.get("bid_state").toString();
												if(j==0){
													stateid = _bid_state;
											}
											}											
											if(_bid_state.equals("0")){
												state="未中标";
											}else if(_bid_state.equals("1")){
												state="中标";											
											}
											
										
					%>
          <TR >
            <Td align=middle bgColor=#ffffff><%=user_name%></Td>
            <Td align=middle bgColor=#ffffff><strong><%=bid_price%></strong></Td>
            <Td align=middle bgColor=#ffffff><%=bid_time%></Td>
            <Td align=middle bgColor=#ffffff><strong><%=state%> <a id="buy<%=j%>" href="/templets/html/shop/jsp/shopingServices.jsp?type_id=<%=_auction_id%>&cust_id=<%=cust_id%>&goods_props=<%=attr_desc%>&goods_id=<%=good_id%>&goodsprice=<%=bid_price%>&buy_num=1&type=2" style="display:none" > 购买 </a></strong> </Td>
          </TR>
          <script>
						if("<%=_bid_state%>"=="1"&&"<%=user_id%>"=="<%=_user_id%>"){
							document.getElementById("buy<%=j%>").style.display="block";
							document.getElementById("show_paimai").innerHTML="已经有人竞标，该活动结束！";
						}
					</script>
          <%
						}}
					%>
          <TR>
            <TD align=middle bgColor=#ffffff colspan="4" ><%=pageString%></TD>
          </TR>
        </TBODY>
      </TABLE>
    </DIV>
  </DIV>
</DIV>
</DIV>
</DIV>
</DIV>
<script>
	function subForm(){
		var user_id='<%=user_id%>';
		var user_type='<%=user_type%>';
		if(user_id==''||user_type!='2'){
			//alert("您还没有登录，不能出价！");
			document.location.href="/shop_signin.html";
			return false;	
		}
		if(1<%=stateid%>=="11"||new Date()<<%=end_date%>){
					alert("该活动已经结束");
					return false;		
		}    
		var rate_price = document.getElementById('rate_price').value;
		var max_price = document.getElementById('max_price').value;
		var for_price = parseFloat(rate_price) + parseFloat(max_price);
		
		//var bid_price_user = document.getElementById('bid_price_user').value;
		var a_price = document.getElementById('a_price').value;
		
		var bid_price = document.getElementById('bid_price').value;
		//alert(bid_price+"   "+"a_price=="+a_price);
		if(bid_price==''){
			alert('请输入出价的金额!');
			document.getElementById('bid_price').focus();
			return false;
		}else if(isNaN(bid_price)){
			alert('请输入数字!');
			document.getElementById('bid_price').focus();
			return false;
		}else if(for_price > bid_price){
			alert('您输入的金额不能少于'+for_price+'!');
			document.getElementById('bid_price').focus();
			return false;
		}else if(parseFloat(bid_price) >= parseFloat(a_price)){
				document.getElementById('bid_price').value = bid_price;
				document.getElementById('bid_state').value = '1'; //立即中标
				//alert(document.getElementById('bid_state').value);
				alert("恭喜,中标！");
		}
		//return false;
		document.theForm.submit();
	}
</script>
<!--底部开始-->
<jsp:include page="/templets/html/shop/footer.jsp"/>
<!--底部结束-->
</div>
</body>
</html>
